package com.javasm.adminapi.login.service.impl;

import com.javasm.adminapi.login.model.LoginUser;
import com.javasm.adminapi.module.system.entity.User;
import com.javasm.adminapi.module.system.service.UserService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @className: UnameUserDetailsService
 * @description:
 * @author: zcx
 * @date: 2025/10/16 15:51
 * @version: 0.1
 * @since: jdk17
 */
@Service
public class UnameUserDetailsService implements UserDetailsService {
    @Resource
    UserService userService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User byUsername = userService.getByUsername(username);
        if (byUsername == null){
            return null;
        }
        return new LoginUser(byUsername);
    }
}
